home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / man2txt.zip / MAN2TXT.C next >
C/C++ Source or Header  |  1996-10-01  |  1KB  |  67 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.     FILE *in, *out;
  9.     int i;
  10.     int buf[1024];
  11.  
  12.     i=0;
  13.  
  14.     if(argc != 3)
  15.     {
  16.       fprintf(stderr, "Usage: man2txt [man page] [output file]\n");
  17.       exit(1);
  18.     }
  19.  
  20.     if( stricmp(argv[1], argv[2])==0 )
  21.     {
  22.       fprintf(stderr, "[man page] and [output file] can not be the same.\n");
  23.       exit(1);
  24.     }
  25.  
  26.     if ((in = fopen(argv[1], "r+b")) == NULL)
  27.     {
  28.         fprintf(stderr, "Cannot open input file.\n");
  29.         return 1;
  30.     }
  31.  
  32.     if ((out = fopen(argv[2], "w+b")) == NULL)
  33.     {
  34.         fprintf(stderr, "Cannot open output file.\n");
  35.         return 1;
  36.     }
  37.  
  38.     while(!feof(in))
  39.     {
  40.         while((buf[i]=fgetc(in))!=0x0D && !feof(in))
  41.         {
  42.             if(buf[i] == 8 && i > 0)
  43.             {
  44.                 buf[--i]=fgetc(in);
  45.                 i++;
  46.             }
  47.             else i++;
  48.         }
  49.  
  50.         if(!feof(in))
  51.         {
  52.             for(i=0;buf[i]!=0x0D;i++)
  53.             {
  54.                 fputc(buf[i], out);
  55.             }
  56.  
  57.             fputc(buf[i], out);
  58.             i=0;
  59.         }
  60.     }
  61.  
  62.     fclose(in);
  63.     fclose(out);
  64.  
  65.     return 0;
  66. }
  67.